import { Injectable, Inject } from '@nestjs/common';
import { Model ,Document} from 'mongoose';
import { Photo } from 'src/db/schemas/photo.schema';
import { AddPhoto ,EditPhoto , DeletePhoto } from './photo.dto'

/**相册模块服务 */
@Injectable()
export class PhotoService {
	constructor(
		@Inject('PHOTO_MODEL')
		private readonly PhotoModel: Model<Photo>,
	) { }

	async findPhoto(): Promise<Photo[]> {
		return await this.PhotoModel.find().populate('user');
	}

	async addPhoto(Dto: AddPhoto){
		var photo=new this.PhotoModel(Dto)
		return await photo.save()
	}

	async updatePhoto(id:string,params){
		return this.PhotoModel.findByIdAndUpdate(id,params)
	}

	async deletePhoto(id:string){
		return this.PhotoModel.remove({_id:id})
	}
}
